require(["../../conf/config.js"], function(){
	
	require(["jquery"], function(){
		
		$(function(){
						
			function CodeButton(params){
				
				this.init(params);
			};
			
			CodeButton.prototype = {
				
				init(params){
					
					this.$ele = $(params.eleStr);
					this.$ele.attr("value",params.normalText);
					this.timeout = params.timeout;
					this.normalText = params.normalText;
					this.currentTime = params.timeout;
					this.callback = params.callback;
					
					this.$ele.on("click",()=>{
						
						this.beginCountDown();
					});
				},
				beginCountDown(){
					
					if(this.currentTime < this.timeout){
						
						return;
					}
					
					if(this.callback){
						
						this.callback();
					}
					
					clearInterval(this.timer);
					
					this.$ele.attr("value",this.currentTime+"秒");
					
					this.currentTime --;
					
					this.timer = setInterval(()=>{
						
						this.$ele.attr("value",this.currentTime+"秒");
						
						if(this.currentTime < 0){
							
							clearInterval(this.timer);
							
							this.currentTime = this.timeout;
							
							this.$ele.attr("value",this.normalText);
							
							return;
						}
						
						this.currentTime --;
						
					},1000);
				}
			};
			
			let params = {
				
				eleStr  : "input.codeBtn",
				timeout : 10,
				normalText : "获取验证码",
				callback : function(){
					
					sendCode();
					
				}
			};
			
			
			new CodeButton(params);
			
			//发送验证码
			function sendCode(){
				
				$.ajax({
					url:"http://localhost:8000/login/code?mobile=18613858988&tpl_id=184311&tpl_value=#code#=1235&key=91339a1f3b04fbdd432e1730843fe2cd",
					success:function(data){
						console.log("success"+data);
						
						// for(let idx in data){
						// 	
						// 	console.log(data[idx]);
						// }
						
						// let htmlStr = template("goodsList", {
						// 					list: data
						// 			});
						// 		
						// $("ul.displayZone2List").html(htmlStr);
					},
					error:function(xhr,status,error){
						
						console.log("faild"+error);
					}
					
				});
			}
			
			
			
			
			
			
			
		});
		
	})
});